#include<stdio.h>
int main()
{
	int m, n, count;
	count = 0;
	int sz = 0;
	scanf("%d%d", &m, &n);
	int a[100] = { 0 };
	while (1) {
		sz = 0;
		for (int i = 0; i < m; i++) {
			if (a[i] != -1 && count == n - 1) {
				a[i] = -1;
				count = 0;
			}
			if (a[i] != -1)
				count++;
		}

		for (int j = 0; j < m; j++) {
			if (a[j] == 0)
				sz++;
		}
		if (sz == 1)
			break;
	}
	for (int i = 0; i < m ; i++) {
		if (a[i] == 0)
			printf("%d\n", i);
	}
}